#include "dialogSmbLogin.h"
#include "ui_dialogSmbLogin.h"
#ifdef Q_OS_ANDROID
DialogSMBLogin::DialogSMBLogin(QWidget* parent)
{

    ui = new Ui::dialogSmbLogin;
    ui->setupUi(this);

    this->setParent(parent);
    this->setMinimumSize(QSize(200, 200));

    _line_ip = ui->lineEdit_ip;
    _line_usr = ui->lineEdit_usr;
    _line_pwd = ui->lineEdit_pwd;
    _label_info = ui->label_info;


    _button_connect = ui->button_connect;
    _button_cancel = ui->button_cancel;

    connect(_button_connect, SIGNAL(clicked()), this, SLOT(on_buttonConnect_clicked()));
    connect(_button_cancel, SIGNAL(clicked()), this, SLOT(on_buttonCancel_clicked()));

}

void DialogSMBLogin::showEvent(QShowEvent *event){

    _label_info->setText("");
    _line_usr->setText("");
    _line_ip->setText("");
    _line_pwd->setText("");

    QWidget::showEvent(event);
    this->setGeometry((((QWidget*)this->parent())->width()-this->width())/2,
                      (((QWidget*)this->parent())->height()-this->height())/2 - 20,
                      this->width(),
                      this->height());
}


void DialogSMBLogin::on_buttonConnect_clicked(){


    QString username = _line_usr->text();
    QString ip = _line_ip->text();
    QString password = _line_pwd->text();

    if(ip.size() < 7){
        _label_info->setText("请输入正确的ip");
        return;
    }


    _label_info->setText("连接中，请等待一分钟....");
    QTimer::singleShot(100, [=](){
        if(SMBManager::I().addConnection(ip, username, password)){
            qDebug()<< "发送连接成功信号";
            emit sig_connectSuccess(ip);
            this->close();
        }else{
            _label_info->setText("连接失败");
        }
    });


}

void DialogSMBLogin::on_buttonCancel_clicked(){
    this->close();
}
#endif


